package com.demo.controller;


import com.demo.response.Result;
import com.demo.service.impl.ActionServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 功能表 前端控制器
 * @author zm
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/action")
@Slf4j
@Api(tags = "系统权限类")
public class ActionController {
    @Resource
    ActionServiceImpl actionService;

    @ApiOperation(value = "查询权限列表")
    @GetMapping("/getAction")
    public Result getAction(){
        return Result.success(actionService.getAction());
    }


    @PostMapping("/getAction2")
    public Result getAction2(){
        try{
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            HttpServletRequest request = requestAttributes.getRequest();

            StringBuffer sb = new StringBuffer() ;
            InputStream is = request.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String s = "" ;
            while((s=br.readLine())!=null){
                sb.append(s) ;
            }
            String result =sb.toString();
            log.info("\n\n ----------- 请求 json 为 :"+result);
        }catch (Exception e){
            e.printStackTrace();
        }

        return Result.success(actionService.getAction());
    }

}
